<template>
  <div class="list">
    <!-- <div class="pager-title">{{$route.meta.title}}</div> -->
    <el-form size="small" :inline="true" :model="whereData" class="search-from">
      <el-form-item>
        <el-input @keyup.enter.native="init()" clearable v-model="whereData.username" placeholder="用户账号"></el-input>
      </el-form-item>
      <!-- <el-form-item>
        <el-input @keyup.enter.native="fetchData()" clearable v-model="whereData.phone" placeholder="联系方式"></el-input>
      </el-form-item> -->
      <el-form-item>
        <el-date-picker
          style="width: 280px"
          v-model="whereData.created_at"
          type="daterange"
          range-separator="-"
          value-format="yyyy-MM-dd"
          start-placeholder="注册日期(开始)"
          end-placeholder="注册日期(结束)"
          :picker-options="pickerOptions"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="init()">查询</el-button>
      </el-form-item>
    </el-form>
    <div class="section">
      <el-table
        :data="tableData"
        v-loading="isLoading"
        style="width: 100%">
        <el-table-column
          align="center"
          prop="username"
          label="登录号">
        </el-table-column>
        <el-table-column
          align="center"
          show-overflow-tooltip
          prop="member_info.real_name"
          label="姓名">
        </el-table-column>
        <el-table-column
          sortable="custom"
          align="center"
          show-overflow-tooltip
          prop="member_info.id_card"
          label="身份证号码">
        </el-table-column>
        <el-table-column
          sortable="custom"
          align="center"
          show-overflow-tooltip
          prop="member_info.alipay_account"
          label="支付宝账号">
        </el-table-column>
        <el-table-column
          sortable="custom"
          align="center"
          show-overflow-tooltip
          prop="member_info.bank_number"
          label="银行账号">
        </el-table-column>
        <el-table-column
          sortable="custom"
          align="center"
          show-overflow-tooltip
          prop="member_info.real_name_status"
          label="实名认证">
          <template slot-scope="scope">
            <span v-if="scope.row.member_info.real_name_status === -1" style="color: #F56C6C">未认证</span>
            <span v-else-if="scope.row.member_info.real_name_status === 1">已认证</span>
          </template>
        </el-table-column>
        <el-table-column
          sortable="custom"
          align="center"
          show-overflow-tooltip
          prop="member_info.created_at"
          label="入驻时间">
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="pageIndex"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        :total="totalPage"
        layout="total, sizes, prev, pager, next, jumper">
      </el-pagination>
    </div>
  </div>
</template>
<script>
import { mapGetters } from 'vuex'
export default {
  name: 'list',
  data() {
    return {
      whereData: {
        username: '',
        created_at: '',
      },
      isLoading: false,
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      tableData: [],
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      }
    }
  },
  computed:{
    ...mapGetters([
      'userInfo'
    ])
  },
  mounted() {
    this.init()
  },
  methods: {
    init() {
      this.$http.get('/company/member/list',{
        'username': this.whereData.username,
        'created_at': this.whereData.created_at,
        'page': this.pageIndex,
        'limit': this.pageSize
      }).then(res => {
        if (res.code === 0) {
          console.log(res)
          this.tableData = res.page.list
          this.totalPage = res.page.totalCount
          this.amountData = res.amount
        }
      })
    },
    // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.init()
    },
    // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val
      this.init()
    }
  }
}
</script>
<style lang="less" scoped>
.uploader {
  display: inline-block;
  margin-left: 10px;
}
</style>
